package com.baimawangzi.recovery.servlet.activity;

import com.baimawangzi.recovery.service.impl.ActivityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/activitydelete.do")
public class ActivityDeleteServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ActivityServiceImpl activityService = new ActivityServiceImpl();
        //解析url参数
        int id = Integer.parseInt(req.getParameter("id"));
        System.out.println(id);
        int a = activityService.delete(id);
        if(a>0){//返回的信息
            req.setAttribute("msg","删除活动成功");
        }
        else {
            req.setAttribute("msg","删除活动失败");
        }
        try {
            req.getRequestDispatcher("activitylist.do").forward(req,resp);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
